﻿@if (false) {<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.7.min.js" type="text/javascript" />}
@{string list = "list17", pager = "pager17", entity = "OrderItem";}
<table id="@list" class="scroll" cellpadding="0" cellspacing="0">
</table>
<div id="@pager" class="scroll" style="text-align: center;">
</div>
<div title="添加入库记录" id="indepository" class="ui-jqdialog-content ui-widget-content">
<table class="EditTable ui-jqdialog-content" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr id="FormError" style="display:none"><td></td><td></td></tr>
<tr class="tinfo" style="display:none"><td></td><td></td></tr>

<tr class="FormData" rowpos="1"><td class="CaptionTD">入库数量</td><td class="DataTD"><input id="count" class="FormElement ui-widget-content ui-corner-all" type="text" /><span style="color:red">*</span></td></tr>
<tr class="FormData" rowpos="2"><td class="CaptionTD">入库日期</td><td class="DataTD"><input id="date" class="FormElement ui-widget-content ui-corner-all" type="text" /><span style="color:red">*</span></td></tr>
<tr class="FormData" rowpos="3"><td class="CaptionTD">批次号</td><td class="DataTD"><input id="number" class="FormElement ui-widget-content ui-corner-all" type="text" /><span style="color:red">*</span></td></tr>
<tr class="FormData" rowpos="4"><td class="CaptionTD">存放货柜</td><td class="DataTD"><input id="location" class="FormElement ui-widget-content ui-corner-all" type="text" /><span style="color:red">*</span></td></tr>
<tr class="FormData" rowpos="5"><td class="CaptionTD">备注</td><td class="DataTD"><textarea id="remark" class="FormElement ui-widget-content ui-corner-all" name="Remark" cols="20" rows="2" role="textbox" multiline="true"></textarea></td></tr>
</tbody>
</table>
</div>
<script type="text/javascript">
    jQuery(function () {
    $("#date").datepicker();
    $("#indepository").dialog({
            autoOpen: false,
            height: 280,
            width: 280,
            modal: true,
            buttons: {
                "保存": function () {
                    if($("#count").val()==""){ Alert("警告","字段不能为空！"); return; }
                    if($("#number").val()==""){ Alert("警告","字段不能为空！"); return; }
                    if($("#location").val()==""){ Alert("警告","字段不能为空！"); return; }
                    var id = $("#@list").jqGrid('getGridParam', 'selrow');
                    var data = {"OrderItemId": id, "date": $("#date").val(), "count": $("#count").val(), "number": $("#number").val(), "location": $("#location").val(), "remark": $("#remark").val()};
                    $.post("/Depository/PMAdd", data, function(d){
                        if(d.success){
                            $("#@list").trigger("reloadGrid");
                            $("#date").val("");
                            $("#count").val("");
                            $("#number").val("");
                            $("#location").val("");
                            $("#remark").val("");
                            $("#indepository").dialog("close");
                        }else{
                            Alert("出错", d.message);
                        }
                    });
                },
                "取消": function () {
                    $(this).dialog("close");
                }
            }
        });
        $("#@list").jqGrid({
            url: "/@entity/index/",
            colNames: ["物料编号", "配件名称", "规格", "数量", "单位",
            @if(Roles.IsUserInRole("purchasemanagers")){
                @:"单价", "总价", 
            }
             "已入库数量", "采购编号", "供应商编号", "供应商名称"],
            colModel: [
            $.jgridx.strCol("ProductValueObject.Number"),
            $.jgridx.strCol("ProductValueObject.Name"),
            $.jgridx.strNullCol("ProductValueObject.Model"),
            $.jgridx.intCol("Count"),
            $.jgridx.strNullCol("ProductValueObject.Unit"),
            @if(Roles.IsUserInRole("purchasemanagers")){
                @:$.jgridx.intCol("Price"),
                @:$.extend($.jgridx.intCol("Total"), { search: false }),
            }
            $.jgridx.intCol("InDepositoryCount"),
            $.jgridx.strCol("Order.Number"),
            $.jgridx.strCol("Order.Supplier.Number"),
            $.jgridx.strNullCol("Order.Supplier.Name"),
            ],

            pager: $('#@pager'),
            sortname: "@(entity)Id",
            sortorder: "desc",

            loadComplete: function (data) {

                if (!data.success)
                    $(this).jqGrid("clearGridData", true);
            }
        });
        $("#@list").jqGrid('navGrid', '#@pager',
        {
            edit: false,
            add: false,
            search: true,
            del: false,
            refresh: true
        },
        {
            url: "/@entity/edit/"
        },
        {
            url: "/@entity/add/"
        },
        {
            url: "/@entity/delete/"
        }, {}, {}).navSeparatorAdd("@pager", { sepclass: "ui-separator", sepcontent: '' })
        .jqGrid('navButtonAdd', "@pager", { caption: "",
            buttonicon: "ui-icon ui-icon-print",
            position: "last",
            title: "打印采购项",
            onClickButton: function () {
                var rowids = $("#@list").jqGrid('getGridParam', 'selarrrow');
                if (rowids.length == 0) {
                    Alert("警告", "请选择记录！");
                    return;
                }
                var title = "采购项一览"
                var p = $("#@list");
                var h = p.parent().parent().parent().find("table").eq(0).find("thead");
                var printhtml = []
                printhtml.push(h.html());
                $.each(p.find("tr"), function (index, value) {
                    if (inarray(rowids, $(this).attr("id"))) {
                        printhtml.push("<tr>" + $(this).html() + "</tr>");
                    }
                });

                var printdiv = $('<div id="printdiv"><h1>' + title + '</h1><table cellspacing="0" cellpadding="0" border="0">' + printhtml.join('') + '</table></div>');
                $.each(printdiv.find("tr"), function () {
                    $(this).children().eq(0).remove();
                });
                printdiv.find("span").remove();
                Print(printdiv);
            }
        })
        @if(Roles.IsUserInRole("depositoryusers")){
        <text>
        .jqGrid('navButtonAdd', "@pager", { caption: "",
            buttonicon: "ui-icon ui-icon-plus",
            position: "last",
            title: "采购入库",
            onClickButton: function () {
                var rowid = $("#@list").jqGrid('getGridParam', 'selrow');
                if (rowid == null) {
                    Alert("警告", "请选择记录！");
                    return;
                }
                $("#indepository").dialog("open");
            }
        })</text>
        }
        ;
    });
</script>